using MediatR;
using RBAC.ErrorCode;
using System.ComponentModel.DataAnnotations;

namespace RBAC.Write.Api.Application.Command.ERP.SalesManagement
{
    /// <summary>
    /// 编辑销售订单命令
    /// </summary>
    public class UpdateSalesOrderCommand : IRequest<APIResult<bool>>
    {
        /// <summary>
        /// 销售订单ID
        /// </summary>
        [Required(ErrorMessage = "销售订单ID不能为空")]
        public long Id { get; set; }

        /// <summary>
        /// 单据类型：业务订单、计划生产、预计
        /// </summary>
        [Required(ErrorMessage = "单据类型不能为空")]
        public string OrderType { get; set; } = "业务订单";

        /// <summary>
        /// 单据日期
        /// </summary>
        [Required(ErrorMessage = "单据日期不能为空")]
        public DateTime OrderDate { get; set; }

        /// <summary>
        /// 业务类型
        /// </summary>
        [Required(ErrorMessage = "业务类型不能为空")]
        public string BusinessType { get; set; } = "销售订单";

        /// <summary>
        /// 业务状态：正常/暂停/取消
        /// </summary>
        public string BusinessStatus { get; set; } = "正常";

        /// <summary>
        /// 销售部门
        /// </summary>
        public string? SalesDepartment { get; set; }

        /// <summary>
        /// 销售人员Id
        /// </summary>
        public long? SalesPersonId { get; set; }

        /// <summary>
        /// 销售人员
        /// </summary>
        public string? SalesPerson { get; set; }

        /// <summary>
        /// 销售类型：国内品牌/国外品牌/代理
        /// </summary>
        public string SalesChannel { get; set; } = "国内品牌";

        /// <summary>
        /// 供货方式：自产/采购/委外
        /// </summary>
        public string SupplyMode { get; set; } = "计划生产";

        /// <summary>
        /// 客户名称
        /// </summary>
        [Required(ErrorMessage = "客户名称不能为空")]
        public string CustomerName { get; set; }

        /// <summary>
        /// 收货人
        /// </summary>
        public string? Receiver { get; set; }

        /// <summary>
        /// 电话
        /// </summary>
        public string? Phone { get; set; }

        /// <summary>
        /// 地址
        /// </summary>
        public string? Address { get; set; }

        /// <summary>
        /// 目的国家
        /// </summary>
        public string? DestinationCountry { get; set; }

        /// <summary>
        /// 合同号
        /// </summary>
        public string? ContractNo { get; set; }

        /// <summary>
        /// 付款条件：账期、预付款、月结
        /// </summary>
        public string? PaymentTerms { get; set; }

        /// <summary>
        /// 交付日期
        /// </summary>
        public DateTime? DeliveryDate { get; set; }

        /// <summary>
        /// 交期状态：确认/未确认/延期
        /// </summary>
        public string DeliveryStatus { get; set; } = "确认";

        /// <summary>
        /// 备注信息
        /// </summary>
        public string? Remark { get; set; }

        /// <summary>
        /// 销售订单明细列表
        /// </summary>
        [Required(ErrorMessage = "销售订单明细不能为空")]
        [MinLength(1, ErrorMessage = "至少需要一条明细")]
        public List<UpdateSalesOrderDetailCommand> Details { get; set; } = new List<UpdateSalesOrderDetailCommand>();
    }

    /// <summary>
    /// 编辑销售订单明细命令
    /// </summary>
    public class UpdateSalesOrderDetailCommand
    {
        /// <summary>
        /// 物料ID
        /// </summary>
        [Required(ErrorMessage = "物料ID不能为空")]
        public long MaterId { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        [Required(ErrorMessage = "数量不能为空")]
        [Range(1, int.MaxValue, ErrorMessage = "数量必须大于0")]
        public int Num { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        [Required(ErrorMessage = "单价不能为空")]
        [Range(0, double.MaxValue, ErrorMessage = "单价不能为负数")]
        public decimal Price { get; set; }

        /// <summary>
        /// 备注信息
        /// </summary>
        public string? Remark { get; set; }
    }
}
